﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using cmsservice.Entity;
using cmsservice.DAL;
using cmsservice.Common;

namespace cmsservice.BLL
{
    public class BlockRStockBLL
    {
        public List<string> GetBlockByStock(string stock)
        {
            var lst = GetALL();
            var c= lst.Find(x => x.SecuCode==stock);
            if (c != null)
            {
                var bkid=c.BlockCode;
                return lst.Where(x=>x.BlockCode==bkid).Select(x=>x.SecuCode).ToList();
            }
            else
            {
                return new List<string>() { stock };
            }
            
        }

        public BlockRStock GetBKByStock(string stock)
        {
            var lst = GetALL();
            return lst.Find(x => x.SecuCode == stock);
        }

        private List<BlockRStock> GetALL()
        {
            string key = "cmsservice.BLL.BlockRStockBLL.GetALL";
            var lst= Cache.Get<List<BlockRStock>>(key);
            if (lst == null || lst.Count == 0)
            {
                BlockRStockDAL dal = new BlockRStockDAL();
                lst = dal.GetAll();
                if (lst != null && lst.Count > 0)
                {
                    Cache.Add(key, lst, DateTime.Now.AddHours(2));
                }
            }
            return lst;
        }
    }
}
